package com.chunyu.ask.util;

import javax.mail.MessagingException;

import com.chunyu.tool.Eml;
 
 

public class SendEmail implements Runnable{

	private String sendServer;
	private String sendEmail;
	private String sendPassword; 
	private EmailParams params;
	
	
	public SendEmail(EmailParams params){
		this.params = params; 
		//此处获取配置文件中的发送参数配置
//		sendServer = app.getProp("sendServer");
//		sendEmail = app.getProp("sendEmail");
//		sendPassword = app.getProp("sendPassword");
	} 
	
	public void run() {  
		try {
			if(params.toEmail != null && !params.toEmail.isEmpty()){  
				Eml email = new Eml(sendServer, sendEmail, sendEmail, sendPassword);
				email.setSubject(params.subject);
				email.setBody(params.content);  
				for(String to : params.toEmail){  
					email.addTo(to);
				}  
				email.send();
			}
		} catch (MessagingException e) { 
			e.printStackTrace(); 
		}
	} 
 
}
